package com.stlm2.controller;

import com.stlm2.dems.service.DdmGoodsService;
import com.stlm2.dems.service.GoodsValueAddedServicesService;
import com.stlm2.util.codecontent.CodeContent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by zlq on 2017/10/18.
 */
@Controller
@RequestMapping("/goodsValueAddedServicesC")
public class GoodsValueAddedServicesController {
    @Resource
    private GoodsValueAddedServicesService goodsValueAddedServicesService;
    /*
   *zlq
   * 商品添加增值服务
   * token:
   * goodsId:商品ID
   * valueAddedServicesId:增值服务ID
   * warrantyPeriod：总有效期(单位 / 月)
    */
    @ResponseBody
    @RequestMapping(value="/add.json",produces="application/json;charset=UTF-8")
    public  String add(ModelMap model, String token,String goodsId,String valueAddedServicesId,String warrantyPeriod){
        String data=null;
        try {
            data=goodsValueAddedServicesService.add(model,token, goodsId,valueAddedServicesId, warrantyPeriod);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"添加失败",data);
        }
        return  data;
    }

    /*
    *商品删除增值服务
    * zlq
    * token:
    * id: 记录ID
     */
    @ResponseBody
    @RequestMapping(value="/delete.json",produces="application/json;charset=UTF-8")
    public  String delete(ModelMap model, String token,String id){
        String data=null;
        try {
            data=goodsValueAddedServicesService.delete(model,token, id);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"删除失败",data);
        }
        return  data;
    }



    /*
*zlq
* 商品查找叮当猫增值服务列表
* token:
* goodsId:商品ID
*/
    @ResponseBody
    @RequestMapping(value="/getlist.json",produces="application/json;charset=UTF-8")
    public  String getlist(ModelMap model, String token,String goodsId) {
        String data=null;
        try {
            data=goodsValueAddedServicesService.getlist(model,token, goodsId);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }
}
